package main

import (
	"database/sql"
	"fmt"
	"log"
	"net/http"

	_ "github.com/go-sql-driver/mysql"
	"github.com/gorilla/mux"
)

var db = &sql.DB{}

func init() {
	db, err := sql.Open("mysql", "root:123456@tcp(localhost:3306)/confession?charset=utf8")

	if err != nil {
		fmt.Println(err)
	}

	defer db.Close()
}

func main() {
	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/shy/send", ShySend)
	router.HandleFunc("/shy/getlist/{name}", GetList)

	log.Fatal(http.ListenAndServe(":8080", router))
}

func ShySend(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintln(w, "Todo show:")
}

func GetList(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	name := vars["name"]
	fmt.Fprintln(w, "Todo show:", name)

	db.Query("SELECT id, pid, name, question, answer, content, is_open FROM shy_mail WHERE name = 'name'")
	defer rows.Close()
	for rows.Next() {
		//		var name string
		//		var id int
		//		if err := rows.Scan(&id, &name); err != nil {
		//			log.Fatal(err)
		//		}
		//fmt.Printf("name:%s ,id:is %d\n", name, id)
	}

}
